<?php
class NavDao {
	private $table = 'nav' ;
	public function get($id){
		return ClassManager::getSql()->oneDataCache($this->table, 'id',intval($id));
	}
	
	public function getByUrl($url){
		return ClassManager::getSql()->onedata($this->table, "*","where url='".$url."'");
	}
	
	public function getByControl($control,$id){
		return ClassManager::getSql()->onedata($this->table, "*","where url='".$control."' and id ='".$id."'");
	}
	
	public function getFirstLinkByFather_id($father_id){
	return ClassManager::getSql()->onedata($this->table, "*","where father_id='".$father_id."' and sort=1 ");
	}
	
	public function getByUrlAndFatherId($url,$father_id){
		return ClassManager::getSql()->onedata($this->table, "*","where father_id='".$father_id."' and url='".$url."'");
	}
	
	public function getByUrlAndChildId($url,$father_id){
		return ClassManager::getSql()->onedata($this->table, "*","where 1=1 and url='".$url."' and  father_id!='".$father_id."'");
	}
	
	public function getListByFatherId($fatherId){
		return ClassManager::getSql()->datalist($this->table,"*","where father_id=".intval($fatherId)." and status=1 order by sort asc");
	}
	
	
	public function getAllListByFatherId($fatherId,$status=1){
		return ClassManager::getSql()->datalist($this->table,"*","where father_id=".intval($fatherId)."  order by sort asc");
	}
	
	public function getByFatherId($fatherId){
		return ClassManager::getSql()->oneDataCache($this->table, 'father_id', intval($fatherId));
	}
	public function add($data){
		ClassManager::getSql()->insert($this->table, $data);
	}
	public function update($data,$id){
		ClassManager::getSql()->updates($this->table, $data,"where id=".intval($id));
	}
	public function deleteBatchByid($id){
		ClassManager::getSql()->delete($this->table,"where id in(".$id.")");
	}
	public function searchList($where=array(),$order='',$limit=0){
		$where = $this->searchWhere($where);
		return ClassManager::getSql()->dataList1($this->table,'*',$where,$order,$limit);
	}
	public function searchWhere($where){
		$where1 = array();
		foreach ($where as  $k=>$v){
			if (!empty($v)){
				$where1[$k] = $v;
			}
		}
		unset($where);
		return $where1;
	}

}
?>